<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>setTimeout clearTimeout</title>
</head>
<body>

    <input type="button" value="显示计时的文本！" onClick="timedText()">

    <input type="button" value="消除计时" onClick="clearTimedText()">
    <br>

    <input type="text" id="txt">

    <script type="text/javascript">

            var t1;
            var t2;
            var t3;

            function timedText() {
                t1 = setTimeout("document.getElementById('txt').value='2 seconds!'", 2000);
                t2 = setTimeout("document.getElementById('txt').value='4 seconds!'", 4000);
                t3 = setTimeout("document.getElementById('txt').value='6 seconds!'", 6000);
            }

            function clearTimedText() {
                clearImmediate(t1);
                clearImmediate(t2);
                clearImmediate(t3);
            }
        </script>

</body>
</html>